<!DOCTYPE html><html lang="zh-CN" data-theme="light"><head><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width,initial-scale=1"><title>若依RuoYi-Vue代码学习一---【DEBUG】登录验证时，Spring Security怎么帮我们查的用户信息 | Program W</title><meta name="keywords" content="ry,前后端分离"><meta name="author" content="Program W"><meta name="copyright" content="Program W"><meta name="format-detection" content="telephone=no"><meta name="theme-color" content="#ffffff"><meta name="description" content="一、登录验证时，Spring Security怎么帮我们查的用户信息 之前说个SysLoginService有登录验证的方法  &#x2F;**     * 登录验证     *      * @param username 用户名     * @param password 密码     * @param code 验证码     * @param uuid 唯一标识     * @return 结果">
<meta property="og:type" content="article">
<meta property="og:title" content="若依RuoYi-Vue代码学习一---【DEBUG】登录验证时，Spring Security怎么帮我们查的用户信息">
<meta property="og:url" content="https://lwstudy.gitee.io/2021/11/25/ry-vue-demo4/index.html">
<meta property="og:site_name" content="Program W">
<meta property="og:description" content="一、登录验证时，Spring Security怎么帮我们查的用户信息 之前说个SysLoginService有登录验证的方法  &#x2F;**     * 登录验证     *      * @param username 用户名     * @param password 密码     * @param code 验证码     * @param uuid 唯一标识     * @return 结果">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="https://lwstudy.gitee.io/img/default.jpg">
<meta property="article:published_time" content="2021-11-25T01:10:30.000Z">
<meta property="article:modified_time" content="2021-12-13T03:23:46.045Z">
<meta property="article:author" content="Program W">
<meta property="article:tag" content="ry">
<meta property="article:tag" content="前后端分离">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="https://lwstudy.gitee.io/img/default.jpg"><link rel="shortcut icon" href="/img/favicon.png"><link rel="canonical" href="https://lwstudy.gitee.io/2021/11/25/ry-vue-demo4/"><link rel="preconnect" href="//cdn.jsdelivr.net"/><link rel="preconnect" href="//busuanzi.ibruce.info"/><link rel="stylesheet" href="/css/index.css"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fortawesome/fontawesome-free/css/all.min.css" media="print" onload="this.media='all'"><script>const GLOBAL_CONFIG = { 
  root: '/',
  algolia: undefined,
  localSearch: undefined,
  translate: undefined,
  noticeOutdate: undefined,
  highlight: {"plugin":"highlighjs","highlightCopy":true,"highlightLang":true,"highlightHeightLimit":false},
  copy: {
    success: '复制成功',
    error: '复制错误',
    noSupport: '浏览器不支持'
  },
  relativeDate: {
    homepage: false,
    post: false
  },
  runtime: '',
  date_suffix: {
    just: '刚刚',
    min: '分钟前',
    hour: '小时前',
    day: '天前',
    month: '个月前'
  },
  copyright: {"limitCount":50,"languages":{"author":"作者: Program W","link":"链接: ","source":"来源: Program W","info":"著作权归作者所有。商业转载请联系作者获得授权，非商业转载请注明出处。"}},
  lightbox: 'fancybox',
  Snackbar: undefined,
  source: {
    jQuery: 'https://cdn.jsdelivr.net/npm/jquery@latest/dist/jquery.min.js',
    justifiedGallery: {
      js: 'https://cdn.jsdelivr.net/npm/justifiedGallery/dist/js/jquery.justifiedGallery.min.js',
      css: 'https://cdn.jsdelivr.net/npm/justifiedGallery/dist/css/justifiedGallery.min.css'
    },
    fancybox: {
      js: 'https://cdn.jsdelivr.net/npm/@fancyapps/fancybox@latest/dist/jquery.fancybox.min.js',
      css: 'https://cdn.jsdelivr.net/npm/@fancyapps/fancybox@latest/dist/jquery.fancybox.min.css'
    }
  },
  isPhotoFigcaption: false,
  islazyload: false,
  isanchor: false
}</script><script id="config-diff">var GLOBAL_CONFIG_SITE = {
  title: '若依RuoYi-Vue代码学习一---【DEBUG】登录验证时，Spring Security怎么帮我们查的用户信息',
  isPost: true,
  isHome: false,
  isHighlightShrink: false,
  isToc: true,
  postUpdate: '2021-12-13 11:23:46'
}</script><noscript><style type="text/css">
  #nav {
    opacity: 1
  }
  .justified-gallery img {
    opacity: 1
  }

  #recent-posts time,
  #post-meta time {
    display: inline !important
  }
</style></noscript><script>(win=>{
    win.saveToLocal = {
      set: function setWithExpiry(key, value, ttl) {
        if (ttl === 0) return
        const now = new Date()
        const expiryDay = ttl * 86400000
        const item = {
          value: value,
          expiry: now.getTime() + expiryDay,
        }
        localStorage.setItem(key, JSON.stringify(item))
      },

      get: function getWithExpiry(key) {
        const itemStr = localStorage.getItem(key)

        if (!itemStr) {
          return undefined
        }
        const item = JSON.parse(itemStr)
        const now = new Date()

        if (now.getTime() > item.expiry) {
          localStorage.removeItem(key)
          return undefined
        }
        return item.value
      }
    }
  
    win.getScript = url => new Promise((resolve, reject) => {
      const script = document.createElement('script')
      script.src = url
      script.async = true
      script.onerror = reject
      script.onload = script.onreadystatechange = function() {
        const loadState = this.readyState
        if (loadState && loadState !== 'loaded' && loadState !== 'complete') return
        script.onload = script.onreadystatechange = null
        resolve()
      }
      document.head.appendChild(script)
    })
  
      win.activateDarkMode = function () {
        document.documentElement.setAttribute('data-theme', 'dark')
        if (document.querySelector('meta[name="theme-color"]') !== null) {
          document.querySelector('meta[name="theme-color"]').setAttribute('content', '#0d0d0d')
        }
      }
      win.activateLightMode = function () {
        document.documentElement.setAttribute('data-theme', 'light')
        if (document.querySelector('meta[name="theme-color"]') !== null) {
          document.querySelector('meta[name="theme-color"]').setAttribute('content', '#ffffff')
        }
      }
      const t = saveToLocal.get('theme')
    
          if (t === 'dark') activateDarkMode()
          else if (t === 'light') activateLightMode()
        
      const asideStatus = saveToLocal.get('aside-status')
      if (asideStatus !== undefined) {
        if (asideStatus === 'hide') {
          document.documentElement.classList.add('hide-aside')
        } else {
          document.documentElement.classList.remove('hide-aside')
        }
      }
    
    const detectApple = () => {
      if (GLOBAL_CONFIG_SITE.isHome && /iPad|iPhone|iPod|Macintosh/.test(navigator.userAgent)){
        document.documentElement.classList.add('apple')
      }
    }
    detectApple()
    })(window)</script><meta name="generator" content="Hexo 5.4.0"></head><body><div id="loading-box"><div class="loading-left-bg"></div><div class="loading-right-bg"></div><div class="spinner-box"><div class="configure-border-1"><div class="configure-core"></div></div><div class="configure-border-2"><div class="configure-core"></div></div><div class="loading-word">加载中...</div></div></div><div id="web_bg"></div><div id="sidebar"><div id="menu-mask"></div><div id="sidebar-menus"><div class="avatar-img is-center"><img src="/img/spider.jpeg" onerror="onerror=null;src='/img/friend_404.gif'" alt="avatar"/></div><div class="site-data"><div class="data-item is-center"><div class="data-item-link"><a href="/archives/"><div class="headline">文章</div><div class="length-num">9</div></a></div></div><div class="data-item is-center"><div class="data-item-link"><a href="/tags/"><div class="headline">标签</div><div class="length-num">10</div></a></div></div><div class="data-item is-center"><div class="data-item-link"><a href="/categories/"><div class="headline">分类</div><div class="length-num">9</div></a></div></div></div><hr/><div class="menus_items"><div class="menus_item"><a class="site-page" href="/"><i class="fa-fw fas fa-home"></i><span> 首頁</span></a></div><div class="menus_item"><a class="site-page" href="/archives/"><i class="fa-fw fas fa-archive"></i><span> 时间轴</span></a></div><div class="menus_item"><a class="site-page" href="/tags/"><i class="fa-fw fas fa-tags"></i><span> 标签</span></a></div><div class="menus_item"><a class="site-page" href="/categories/"><i class="fa-fw fas fa-folder-open"></i><span> 分类</span></a></div><div class="menus_item"><a class="site-page" href="javascript:void(0);"><i class="fa-fw fa fa-heartbeat"></i><span> 其他</span><i class="fas fa-chevron-down expand"></i></a><ul class="menus_item_child"><li><a class="site-page child" href="/music/"><i class="fa-fw fas fa-music"></i><span> 音乐</span></a></li><li><a class="site-page child" href="/Gallery/"><i class="fa-fw fas fa-images"></i><span> 照片</span></a></li><li><a class="site-page child" href="/movies/"><i class="fa-fw fas fa-video"></i><span> 电影</span></a></li><li><a class="site-page child" href="/resources/"><i class="fa-fw fa-heartbeat"></i><span> 资源</span></a></li></ul></div><div class="menus_item"><a class="site-page" href="/link/"><i class="fa-fw fas fa-link"></i><span> One Piece</span></a></div><div class="menus_item"><a class="site-page" href="/about/"><i class="fa-fw fas fa-heart"></i><span> 关于</span></a></div></div></div></div><div class="post" id="body-wrap"><header class="post-bg" id="page-header" style="background-image: url('/img/default.jpg')"><nav id="nav"><span id="blog_name"><a id="site-name" href="/">Program W</a></span><div id="menus"><div class="menus_items"><div class="menus_item"><a class="site-page" href="/"><i class="fa-fw fas fa-home"></i><span> 首頁</span></a></div><div class="menus_item"><a class="site-page" href="/archives/"><i class="fa-fw fas fa-archive"></i><span> 时间轴</span></a></div><div class="menus_item"><a class="site-page" href="/tags/"><i class="fa-fw fas fa-tags"></i><span> 标签</span></a></div><div class="menus_item"><a class="site-page" href="/categories/"><i class="fa-fw fas fa-folder-open"></i><span> 分类</span></a></div><div class="menus_item"><a class="site-page" href="javascript:void(0);"><i class="fa-fw fa fa-heartbeat"></i><span> 其他</span><i class="fas fa-chevron-down expand"></i></a><ul class="menus_item_child"><li><a class="site-page child" href="/music/"><i class="fa-fw fas fa-music"></i><span> 音乐</span></a></li><li><a class="site-page child" href="/Gallery/"><i class="fa-fw fas fa-images"></i><span> 照片</span></a></li><li><a class="site-page child" href="/movies/"><i class="fa-fw fas fa-video"></i><span> 电影</span></a></li><li><a class="site-page child" href="/resources/"><i class="fa-fw fa-heartbeat"></i><span> 资源</span></a></li></ul></div><div class="menus_item"><a class="site-page" href="/link/"><i class="fa-fw fas fa-link"></i><span> One Piece</span></a></div><div class="menus_item"><a class="site-page" href="/about/"><i class="fa-fw fas fa-heart"></i><span> 关于</span></a></div></div><div id="toggle-menu"><a class="site-page"><i class="fas fa-bars fa-fw"></i></a></div></div></nav><div id="post-info"><h1 class="post-title">若依RuoYi-Vue代码学习一---【DEBUG】登录验证时，Spring Security怎么帮我们查的用户信息</h1><div id="post-meta"><div class="meta-firstline"><span class="post-meta-date"><i class="far fa-calendar-alt fa-fw post-meta-icon"></i><span class="post-meta-label">发表于</span><time class="post-meta-date-created" datetime="2021-11-25T01:10:30.000Z" title="发表于 2021-11-25 09:10:30">2021-11-25</time><span class="post-meta-separator">|</span><i class="fas fa-history fa-fw post-meta-icon"></i><span class="post-meta-label">更新于</span><time class="post-meta-date-updated" datetime="2021-12-13T03:23:46.045Z" title="更新于 2021-12-13 11:23:46">2021-12-13</time></span><span class="post-meta-categories"><span class="post-meta-separator">|</span><i class="fas fa-inbox fa-fw post-meta-icon"></i><a class="post-meta-categories" href="/categories/ry/">ry</a><i class="fas fa-angle-right post-meta-separator"></i><i class="fas fa-inbox fa-fw post-meta-icon"></i><a class="post-meta-categories" href="/categories/ry/%E5%89%8D%E5%90%8E%E7%AB%AF%E5%88%86%E7%A6%BB/">前后端分离</a></span></div><div class="meta-secondline"><span class="post-meta-separator">|</span><span class="post-meta-pv-cv" id="" data-flag-title="若依RuoYi-Vue代码学习一---【DEBUG】登录验证时，Spring Security怎么帮我们查的用户信息"><i class="far fa-eye fa-fw post-meta-icon"></i><span class="post-meta-label">阅读量:</span><span id="busuanzi_value_page_pv"></span></span></div></div></div></header><main class="layout" id="content-inner"><div id="post"><article class="post-content" id="article-container"><h1 id="一、登录验证时，Spring-Security怎么帮我们查的用户信息"><a href="#一、登录验证时，Spring-Security怎么帮我们查的用户信息" class="headerlink" title="一、登录验证时，Spring Security怎么帮我们查的用户信息"></a>一、登录验证时，Spring Security怎么帮我们查的用户信息</h1><ul>
<li>之前说个<code>SysLoginService</code>有登录验证的方法</li>
</ul>
<figure class="highlight java"><table><tr><td class="code"><pre><span class="line"><span class="comment">/**</span></span><br><span class="line"><span class="comment">     * 登录验证</span></span><br><span class="line"><span class="comment">     * </span></span><br><span class="line"><span class="comment">     * <span class="doctag">@param</span> username 用户名</span></span><br><span class="line"><span class="comment">     * <span class="doctag">@param</span> password 密码</span></span><br><span class="line"><span class="comment">     * <span class="doctag">@param</span> code 验证码</span></span><br><span class="line"><span class="comment">     * <span class="doctag">@param</span> uuid 唯一标识</span></span><br><span class="line"><span class="comment">     * <span class="doctag">@return</span> 结果</span></span><br><span class="line"><span class="comment">     */</span></span><br><span class="line">    <span class="function"><span class="keyword">public</span> String <span class="title">login</span><span class="params">(String username, String password, String code, String uuid)</span></span></span><br><span class="line"><span class="function">    </span>&#123;</span><br><span class="line">        <span class="keyword">boolean</span> captchaOnOff = configService.selectCaptchaOnOff();</span><br><span class="line">        <span class="comment">// 验证码开关</span></span><br><span class="line">        <span class="keyword">if</span> (captchaOnOff)</span><br><span class="line">        &#123;   <span class="comment">//校验验证码</span></span><br><span class="line">            validateCaptcha(username, code, uuid);</span><br><span class="line">        &#125;</span><br><span class="line">        <span class="comment">// 用户验证</span></span><br><span class="line">        Authentication authentication = <span class="keyword">null</span>;</span><br><span class="line">        <span class="keyword">try</span></span><br><span class="line">        &#123;</span><br><span class="line">            <span class="comment">// 该方法会去调用UserDetailsServiceImpl.loadUserByUsername</span></span><br><span class="line">            authentication = authenticationManager</span><br><span class="line">                    .authenticate(<span class="keyword">new</span> UsernamePasswordAuthenticationToken(username, password));</span><br><span class="line">            <span class="comment">//UsernamePasswordAuthenticationToken [Principal=com.ruoyi.common.core.domain.model.LoginUser@748cc4df, Credentials=[PROTECTED], Authenticated=true, Details=null, Granted Authorities=[]]</span></span><br><span class="line"></span><br><span class="line">        &#125;</span><br><span class="line">        <span class="keyword">catch</span> (Exception e)</span><br><span class="line">        &#123;</span><br><span class="line">            <span class="keyword">if</span> (e <span class="keyword">instanceof</span> BadCredentialsException)</span><br><span class="line">            &#123;</span><br><span class="line">                AsyncManager.me().execute(AsyncFactory.recordLogininfor(username, Constants.LOGIN_FAIL, MessageUtils.message(<span class="string">&quot;user.password.not.match&quot;</span>)));</span><br><span class="line">                <span class="keyword">throw</span> <span class="keyword">new</span> UserPasswordNotMatchException();</span><br><span class="line">            &#125;</span><br><span class="line">            <span class="keyword">else</span></span><br><span class="line">            &#123;</span><br><span class="line">                AsyncManager.me().execute(AsyncFactory.recordLogininfor(username, Constants.LOGIN_FAIL, e.getMessage()));</span><br><span class="line">                <span class="keyword">throw</span> <span class="keyword">new</span> ServiceException(e.getMessage());</span><br><span class="line">            &#125;</span><br><span class="line">        &#125;</span><br><span class="line">        <span class="comment">//记录登录信息=====新增系统登录日志</span></span><br><span class="line">        AsyncManager.me().execute(AsyncFactory.recordLogininfor(username, Constants.LOGIN_SUCCESS, MessageUtils.message(<span class="string">&quot;user.login.success&quot;</span>)));</span><br><span class="line"></span><br><span class="line">        LoginUser loginUser = (LoginUser) authentication.getPrincipal();<span class="comment">//com.ruoyi.common.core.domain.model.LoginUser@748cc4df</span></span><br><span class="line"></span><br><span class="line">        <span class="comment">//记录登录信息=====修改用户基本信息(最后IP、时间）</span></span><br><span class="line">        recordLoginInfo(loginUser.getUserId());</span><br><span class="line">        <span class="comment">// 生成token</span></span><br><span class="line">        <span class="keyword">return</span> tokenService.createToken(loginUser);</span><br><span class="line">    &#125;</span><br></pre></td></tr></table></figure>

<blockquote>
<p>今天主要说的是其中的<br><code>authentication = authenticationManager                     .authenticate(new UsernamePasswordAuthenticationToken(username, password));</code><br>                    这一段代码怎么（也就是<code>spring security</code>怎么帮我们查的用户名、密码及用户信息）的【执行流程】===通过<code>DEBUG</code>来仔细看看</p>
</blockquote>
<h1 id="二、开始"><a href="#二、开始" class="headerlink" title="二、开始"></a>二、开始</h1><ul>
<li><p>第一次进入<br><img src="https://img-blog.csdnimg.cn/5a88dea3fcc145cfa972b623fc4b6ecb.png?x-oss-process=image/watermark,type_ZHJvaWRzYW5zZmFsbGJhY2s,shadow_50,text_Q1NETiBAUHJvZ3JhbSBX,size_20,color_FFFFFF,t_70,g_se,x_16" alt="在这里插入图片描述"></p>
</li>
<li><p>走到后面的其中一个方法<code>determineUsername</code>确定用户名，方法位于【抽象用户详细信息身份验证提供者<code>org.springframework.security.authentication.dao.AbstractUserDetailsAuthenticationProvider</code>】</p>
</li>
</ul>
<figure class="highlight java"><table><tr><td class="code"><pre><span class="line"><span class="function"><span class="keyword">private</span> String <span class="title">determineUsername</span><span class="params">(Authentication authentication)</span> </span>&#123;</span><br><span class="line">		<span class="keyword">return</span> (authentication.getPrincipal() == <span class="keyword">null</span>) ? <span class="string">&quot;NONE_PROVIDED&quot;</span> : authentication.getName();</span><br><span class="line">	&#125;</span><br></pre></td></tr></table></figure>
<ul>
<li><p>可以看到这个方法是三目，如果<code>authentication.getPrincipal() == null</code>【用户名不是空】，则<code>getName()</code></p>
</li>
<li><p>上面这个方法在哪里使用呢<br><img src="https://img-blog.csdnimg.cn/7a4cf09ff00e4272879f7e32f0cc9f09.png?x-oss-process=image/watermark,type_ZHJvaWRzYW5zZmFsbGJhY2s,shadow_50,text_Q1NETiBAUHJvZ3JhbSBX,size_20,color_FFFFFF,t_70,g_se,x_16" alt="在这里插入图片描述"></p>
</li>
<li><p>检索用户方法<code>retrieveUser</code>中<br><img src="https://img-blog.csdnimg.cn/4852e87d16a34326b899fab261f9d223.png?x-oss-process=image/watermark,type_ZHJvaWRzYW5zZmFsbGJhY2s,shadow_50,text_Q1NETiBAUHJvZ3JhbSBX,size_20,color_FFFFFF,t_70,g_se,x_16" alt="在这里插入图片描述"></p>
</li>
<li><p>之后走到若依自己的用户服务<code>com.ruoyi.framework.web.service.UserDetailsServiceImpl</code><br><img src="https://img-blog.csdnimg.cn/b79d9ae6175f44489407ba79bc227349.png?x-oss-process=image/watermark,type_ZHJvaWRzYW5zZmFsbGJhY2s,shadow_50,text_Q1NETiBAUHJvZ3JhbSBX,size_20,color_FFFFFF,t_70,g_se,x_16" alt="在这里插入图片描述"></p>
</li>
</ul>
<blockquote>
<p>(<em>^▽^</em>)！！！到这里就没什么好说的了，懂得都懂。</p>
</blockquote>
<ul>
<li><p>接着user变量就有了数据<br><img src="https://img-blog.csdnimg.cn/4b6a71a3dbe64eeaa5fb9cefa2f85bff.png?x-oss-process=image/watermark,type_ZHJvaWRzYW5zZmFsbGJhY2s,shadow_50,text_Q1NETiBAUHJvZ3JhbSBX,size_20,color_FFFFFF,t_70,g_se,x_16" alt="在这里插入图片描述"><br><img src="https://img-blog.csdnimg.cn/5864fe5251254e5ca07a79593eb5cb6f.png?x-oss-process=image/watermark,type_ZHJvaWRzYW5zZmFsbGJhY2s,shadow_50,text_Q1NETiBAUHJvZ3JhbSBX,size_20,color_FFFFFF,t_70,g_se,x_16" alt="在这里插入图片描述"></p>
</li>
<li><p>也可以看看上面，我们之前说的先查<code>username</code>，和没有走缓存<br><img src="https://img-blog.csdnimg.cn/47ab41d059014fa6acd24eddeeee2856.png" alt="在这里插入图片描述"></p>
</li>
<li><p>在查询结束后，还会有一些认证preAuthenticationChecks、preAuthenticationChecks、additionalAuthenticationChecks<img src="https://img-blog.csdnimg.cn/6d17ad3b968641b08fcabea2976e0dc5.png?x-oss-process=image/watermark,type_ZHJvaWRzYW5zZmFsbGJhY2s,shadow_50,text_Q1NETiBAUHJvZ3JhbSBX,size_20,color_FFFFFF,t_70,g_se,x_16"></p>
</li>
<li><p>最后返回【创建成功认证】<code>createSuccessAuthentication</code><br><img src="https://img-blog.csdnimg.cn/2218d551c2c74cb0bfe543ba2cf7525e.png?x-oss-process=image/watermark,type_ZHJvaWRzYW5zZmFsbGJhY2s,shadow_50,text_Q1NETiBAUHJvZ3JhbSBX,size_20,color_FFFFFF,t_70,g_se,x_16" alt="在这里插入图片描述"></p>
</li>
<li><p><code>createSuccessAuthentication</code>方法内部<br><img src="https://img-blog.csdnimg.cn/7a73fb774387411490a7194d637ae5a4.png?x-oss-process=image/watermark,type_ZHJvaWRzYW5zZmFsbGJhY2s,shadow_50,text_Q1NETiBAUHJvZ3JhbSBX,size_20,color_FFFFFF,t_70,g_se,x_16" alt="在这里插入图片描述"></p>
</li>
<li><p>创建认证<br><img src="https://img-blog.csdnimg.cn/d18bc071045248ab9daad223f11d0c38.png?x-oss-process=image/watermark,type_ZHJvaWRzYW5zZmFsbGJhY2s,shadow_50,text_Q1NETiBAUHJvZ3JhbSBX,size_20,color_FFFFFF,t_70,g_se,x_16" alt="在这里插入图片描述"><br>==代码中的官方注解==</p>
<figure class="highlight java"><table><tr><td class="code"><pre><span class="line"><span class="comment">// 确保我们返回用户提供的原始凭据， </span></span><br><span class="line"><span class="comment">// 因此即使使用编码密码，后续尝试也能成功。 </span></span><br><span class="line"><span class="comment">// 还要确保我们返回原始的 getDetails()，以便将来缓存到期后的 </span></span><br><span class="line"><span class="comment">// 身份验证事件包含详细信息</span></span><br></pre></td></tr></table></figure>
<h1 id="三、最后说下一个常用且常见的方法getPrincipal"><a href="#三、最后说下一个常用且常见的方法getPrincipal" class="headerlink" title="三、最后说下一个常用且常见的方法getPrincipal()"></a>三、最后说下一个常用且常见的方法<code>getPrincipal()</code></h1></li>
</ul>
<blockquote>
<p>位于<code>org.springframework.security.authentication.UsernamePasswordAuthenticationToken</code></p>
</blockquote>
<p><img src="https://img-blog.csdnimg.cn/a29af085f04042c3bad422cf7e20a69c.png" alt="在这里插入图片描述"></p>
<ul>
<li><p>这就是<code>getPrincipal()</code>的数据了，就是拿<code>user</code>的<br><img src="https://img-blog.csdnimg.cn/934c1ec0056d42febc15898283bd7912.png?x-oss-process=image/watermark,type_ZHJvaWRzYW5zZmFsbGJhY2s,shadow_50,text_Q1NETiBAUHJvZ3JhbSBX,size_20,color_FFFFFF,t_70,g_se,x_16" alt="在这里插入图片描述"><br><img src="https://img-blog.csdnimg.cn/fbf329905a3b4642857e5a02bb971e0e.png?x-oss-process=image/watermark,type_ZHJvaWRzYW5zZmFsbGJhY2s,shadow_50,text_Q1NETiBAUHJvZ3JhbSBX,size_20,color_FFFFFF,t_70,g_se,x_16" alt="在这里插入图片描述"></p>
</li>
<li><p>然后，挂一张依赖图看看<br><img src="https://img-blog.csdnimg.cn/2804030118c844808a5d7bbcf52f4a5f.png?x-oss-process=image/watermark,type_ZHJvaWRzYW5zZmFsbGJhY2s,shadow_50,text_Q1NETiBAUHJvZ3JhbSBX,size_20,color_FFFFFF,t_70,g_se,x_16" alt="在这里插入图片描述"></p>
</li>
</ul>
<blockquote>
<p>那么，就到这里了。<code>\(^o^)/~!!!</code></p>
</blockquote>
</article><div class="post-copyright"><div class="post-copyright__author"><span class="post-copyright-meta">文章作者: </span><span class="post-copyright-info"><a href="mailto:undefined">Program W</a></span></div><div class="post-copyright__type"><span class="post-copyright-meta">文章链接: </span><span class="post-copyright-info"><a href="https://lwstudy.gitee.io/2021/11/25/ry-vue-demo4/">https://lwstudy.gitee.io/2021/11/25/ry-vue-demo4/</a></span></div><div class="post-copyright__notice"><span class="post-copyright-meta">版权声明: </span><span class="post-copyright-info">本博客所有文章除特别声明外，均采用 <a href="https://creativecommons.org/licenses/by-nc-sa/4.0/" target="_blank">CC BY-NC-SA 4.0</a> 许可协议。转载请注明来自 <a href="https://lwstudy.gitee.io" target="_blank">Program W</a>！</span></div></div><div class="tag_share"><div class="post-meta__tag-list"><a class="post-meta__tags" href="/tags/ry/">ry</a><a class="post-meta__tags" href="/tags/%E5%89%8D%E5%90%8E%E7%AB%AF%E5%88%86%E7%A6%BB/">前后端分离</a></div><div class="post_share"><div class="social-share" data-image="/img/default.jpg" data-sites="facebook,twitter,wechat,weibo,qq"></div><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/social-share.js/dist/css/share.min.css" media="print" onload="this.media='all'"><script src="https://cdn.jsdelivr.net/npm/social-share.js/dist/js/social-share.min.js" defer></script></div></div><nav class="pagination-post" id="pagination"><div class="prev-post pull-left"><a href="/2022/05/06/my-down/"><img class="prev-cover" src="https://s2.loli.net/2022/05/06/eXjyW9FbK2LwxVG.jpg" onerror="onerror=null;src='/img/404.jpg'" alt="cover of previous post"><div class="pagination-info"><div class="label">上一篇</div><div class="prev_info">Java爬虫多线程下载实例</div></div></a></div><div class="next-post pull-right"><a href="/2021/11/24/ry-vue-demo3/"><img class="next-cover" src="https://s2.loli.net/2021/12/10/7jpGreZhuBQ9kLa.jpg" onerror="onerror=null;src='/img/404.jpg'" alt="cover of next post"><div class="pagination-info"><div class="label">下一篇</div><div class="next_info">若依RuoYi-Vue代码学习一---登录实现（验证码校验、token生成，token过滤【验证】）</div></div></a></div></nav><div class="relatedPosts"><div class="headline"><i class="fas fa-thumbs-up fa-fw"></i><span> 相关推荐</span></div><div class="relatedPosts-list"><div><a href="/2021/11/23/ry-vue-demo1/" title="若依RuoYi-Vue代码学习一---注解与切面"><img class="cover" src="https://s2.loli.net/2021/12/10/ux2afMVbTPFZdqz.jpg" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2021-11-23</div><div class="title">若依RuoYi-Vue代码学习一---注解与切面</div></div></a></div><div><a href="/2021/11/23/ry-vue-demo2/" title="若依RuoYi-Vue代码学习一---通用分页处理"><img class="cover" src="https://s2.loli.net/2021/12/10/muYWxT7gpvj1LqB.jpg" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2021-11-23</div><div class="title">若依RuoYi-Vue代码学习一---通用分页处理</div></div></a></div><div><a href="/2021/11/24/ry-vue-demo3/" title="若依RuoYi-Vue代码学习一---登录实现（验证码校验、token生成，token过滤【验证】）"><img class="cover" src="https://s2.loli.net/2021/12/10/7jpGreZhuBQ9kLa.jpg" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2021-11-24</div><div class="title">若依RuoYi-Vue代码学习一---登录实现（验证码校验、token生成，token过滤【验证】）</div></div></a></div></div></div><hr/><div id="post-comment"><div class="comment-head"><div class="comment-headline"><i class="fas fa-comments fa-fw"></i><span> 评论</span></div></div><div class="comment-wrap"><div><div class="vcomment" id="vcomment"></div></div></div></div></div><div class="aside-content" id="aside-content"><div class="card-widget card-info"><div class="is-center"><div class="avatar-img"><img src="/img/spider.jpeg" onerror="this.onerror=null;this.src='/img/friend_404.gif'" alt="avatar"/></div><div class="author-info__name">Program W</div><div class="author-info__description">这是一次开始</div></div><div class="card-info-data"><div class="card-info-data-item is-center"><a href="/archives/"><div class="headline">文章</div><div class="length-num">9</div></a></div><div class="card-info-data-item is-center"><a href="/tags/"><div class="headline">标签</div><div class="length-num">10</div></a></div><div class="card-info-data-item is-center"><a href="/categories/"><div class="headline">分类</div><div class="length-num">9</div></a></div></div><a class="button--animated" id="card-info-btn" target="_blank" rel="noopener" href="https://gitee.com/lwstudy"><i class="fab fa-github"></i><span>Gitee</span></a><div class="card-info-social-icons is-center"><a class="social-icon" href="https://gitee.com/lwstudy" target="_blank" title="Gitee"><i class="fab fa-guilded"></i></a><a class="social-icon" href="https://blog.csdn.net/weixin_46037781" target="_blank" title="CSDN"><i class="fas fa-copyright"></i></a></div></div><div class="card-widget card-announcement"><div class="item-headline"><i class="fas fa-bullhorn card-announcement-animation"></i><span>公告</span></div><div class="announcement_content">我们总得留下些什么吧</div></div><div class="sticky_layout"><div class="card-widget" id="card-toc"><div class="item-headline"><i class="fas fa-stream"></i><span>目录</span></div><div class="toc-content"><ol class="toc"><li class="toc-item toc-level-1"><a class="toc-link" href="#%E4%B8%80%E3%80%81%E7%99%BB%E5%BD%95%E9%AA%8C%E8%AF%81%E6%97%B6%EF%BC%8CSpring-Security%E6%80%8E%E4%B9%88%E5%B8%AE%E6%88%91%E4%BB%AC%E6%9F%A5%E7%9A%84%E7%94%A8%E6%88%B7%E4%BF%A1%E6%81%AF"><span class="toc-number">1.</span> <span class="toc-text">一、登录验证时，Spring Security怎么帮我们查的用户信息</span></a></li><li class="toc-item toc-level-1"><a class="toc-link" href="#%E4%BA%8C%E3%80%81%E5%BC%80%E5%A7%8B"><span class="toc-number">2.</span> <span class="toc-text">二、开始</span></a></li><li class="toc-item toc-level-1"><a class="toc-link" href="#%E4%B8%89%E3%80%81%E6%9C%80%E5%90%8E%E8%AF%B4%E4%B8%8B%E4%B8%80%E4%B8%AA%E5%B8%B8%E7%94%A8%E4%B8%94%E5%B8%B8%E8%A7%81%E7%9A%84%E6%96%B9%E6%B3%95getPrincipal"><span class="toc-number">3.</span> <span class="toc-text">三、最后说下一个常用且常见的方法getPrincipal()</span></a></li></ol></div></div><div class="card-widget card-recent-post"><div class="item-headline"><i class="fas fa-history"></i><span>最新文章</span></div><div class="aside-list"><div class="aside-list-item"><a class="thumbnail" href="/2022/05/06/learn-drools/" title="规则引擎Drools学习与实例"><img src="https://s2.loli.net/2022/05/06/wNBo1Zb9L3npHC8.jpg" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="规则引擎Drools学习与实例"/></a><div class="content"><a class="title" href="/2022/05/06/learn-drools/" title="规则引擎Drools学习与实例">规则引擎Drools学习与实例</a><time datetime="2022-05-06T08:45:21.000Z" title="发表于 2022-05-06 16:45:21">2022-05-06</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/2022/05/06/my-down/" title="Java爬虫多线程下载实例"><img src="https://s2.loli.net/2022/05/06/eXjyW9FbK2LwxVG.jpg" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="Java爬虫多线程下载实例"/></a><div class="content"><a class="title" href="/2022/05/06/my-down/" title="Java爬虫多线程下载实例">Java爬虫多线程下载实例</a><time datetime="2022-05-06T08:33:11.000Z" title="发表于 2022-05-06 16:33:11">2022-05-06</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/2021/11/25/ry-vue-demo4/" title="若依RuoYi-Vue代码学习一---【DEBUG】登录验证时，Spring Security怎么帮我们查的用户信息"><img src="/img/default.jpg" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="若依RuoYi-Vue代码学习一---【DEBUG】登录验证时，Spring Security怎么帮我们查的用户信息"/></a><div class="content"><a class="title" href="/2021/11/25/ry-vue-demo4/" title="若依RuoYi-Vue代码学习一---【DEBUG】登录验证时，Spring Security怎么帮我们查的用户信息">若依RuoYi-Vue代码学习一---【DEBUG】登录验证时，Spring Security怎么帮我们查的用户信息</a><time datetime="2021-11-25T01:10:30.000Z" title="发表于 2021-11-25 09:10:30">2021-11-25</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/2021/11/24/ry-vue-demo3/" title="若依RuoYi-Vue代码学习一---登录实现（验证码校验、token生成，token过滤【验证】）"><img src="https://s2.loli.net/2021/12/10/7jpGreZhuBQ9kLa.jpg" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="若依RuoYi-Vue代码学习一---登录实现（验证码校验、token生成，token过滤【验证】）"/></a><div class="content"><a class="title" href="/2021/11/24/ry-vue-demo3/" title="若依RuoYi-Vue代码学习一---登录实现（验证码校验、token生成，token过滤【验证】）">若依RuoYi-Vue代码学习一---登录实现（验证码校验、token生成，token过滤【验证】）</a><time datetime="2021-11-24T09:10:30.000Z" title="发表于 2021-11-24 17:10:30">2021-11-24</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/2021/11/23/ry-vue-demo2/" title="若依RuoYi-Vue代码学习一---通用分页处理"><img src="https://s2.loli.net/2021/12/10/muYWxT7gpvj1LqB.jpg" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="若依RuoYi-Vue代码学习一---通用分页处理"/></a><div class="content"><a class="title" href="/2021/11/23/ry-vue-demo2/" title="若依RuoYi-Vue代码学习一---通用分页处理">若依RuoYi-Vue代码学习一---通用分页处理</a><time datetime="2021-11-23T09:23:30.000Z" title="发表于 2021-11-23 17:23:30">2021-11-23</time></div></div></div></div></div></div></main><footer id="footer" style="background-image: url('/img/default.jpg')"><div id="footer-wrap"><div class="copyright">&copy;2021 - 2022 By Program W</div><div class="framework-info"><span>框架 </span><a target="_blank" rel="noopener" href="https://hexo.io">Hexo</a><span class="footer-separator">|</span><span>主题 </span><a target="_blank" rel="noopener" href="https://github.com/jerryc127/hexo-theme-butterfly">Butterfly</a></div><div class="footer_custom_text">这里是底部了.请停止下降!</div></div></footer></div><div id="rightside"><div id="rightside-config-hide"><button id="readmode" type="button" title="阅读模式"><i class="fas fa-book-open"></i></button><button id="darkmode" type="button" title="浅色和深色模式转换"><i class="fas fa-adjust"></i></button><button id="hide-aside-btn" type="button" title="单栏和双栏切换"><i class="fas fa-arrows-alt-h"></i></button></div><div id="rightside-config-show"><button id="rightside_config" type="button" title="设置"><i class="fas fa-cog fa-spin"></i></button><button class="close" id="mobile-toc-button" type="button" title="目录"><i class="fas fa-list-ul"></i></button><a id="to_comment" href="#post-comment" title="直达评论"><i class="fas fa-comments"></i></a><button id="go-up" type="button" title="回到顶部"><i class="fas fa-arrow-up"></i></button></div></div><div><script src="/js/utils.js"></script><script src="/js/main.js"></script><script>var preloader = {
  endLoading: () => {
    document.body.style.overflow = 'auto';
    document.getElementById('loading-box').classList.add("loaded")
  },
  initLoading: () => {
    document.body.style.overflow = '';
    document.getElementById('loading-box').classList.remove("loaded")

  }
}
window.addEventListener('load',preloader.endLoading())</script><div class="js-pjax"><script>function loadValine () {
  function initValine () {
    const valine = new Valine(Object.assign({
      el: '#vcomment',
      appId: 'zCYkwMBcHhcNvvPzdsooSPb1-gzGzoHsz',
      appKey: 'MxW3eBpKYaCGdvUxno6EkFuH',
      placeholder: '请留下你的足迹...',
      avatar: 'monsterid',
      meta: 'nick,mail,link'.split(','),
      pageSize: '10',
      lang: 'zh-CN',
      recordIP: false,
      serverURLs: '',
      emojiCDN: '',
      emojiMaps: "",
      enableQQ: false,
      path: window.location.pathname,
      requiredFields: ["nick,mail"],
      visitor: false
    }, null))
  }

  if (typeof Valine === 'function') initValine() 
  else getScript('https://cdn.jsdelivr.net/npm/valine/dist/Valine.min.js').then(initValine)
}

if ('Valine' === 'Valine' || !true) {
  if (true) btf.loadComment(document.getElementById('vcomment'),loadValine)
  else setTimeout(loadValine, 0)
} else {
  function loadOtherComment () {
    loadValine()
  }
}</script></div><script async data-pjax src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script></div></body></html>